class Set {
  constructor() {
    this.items = {}
  }
  has(element) {
    return Object.prototype.hasOwnProperty.call(this.items, element)
  }
  add(element) {
    if (!this.has(element)) {
      this.items[element] = element
      return true
    } else {
      return false
    }
  }
  delete(element) {
    if (this.has(element)) {
      delete this.items[element]
      return true
    } else {
      return false
    }
  }
  clear() {
    this.items = {}
  }
  size() {
    return Object.keys(this.items).length
  }
  values() {
    return Object.values(this.items)
  }
  union(otherSet) { // 并集
    let unionSet = new Set()
    this.values().forEach(item => unionSet.add(item)
    )
    otherSet.values().forEach(item => unionSet.add(item))
    return unionSet
  }
  intersection(otherSet) { // 交集
    let values = this.values()
    let otherSetArr = otherSet.values();
    let bigger = values;
    let smaller = otherSetArr;
    if (values.length < otherSetArr.length) {
      bigger = otherSetArr;
      smaller = values
    }
    let intersectionSet = new Set();
    smaller.forEach(item => {
      if (bigger.includes(item)) {
        intersectionSet.add(item)
      }
    })
    return intersectionSet
  }
  difference(otherSet) { // 差集 包含a有b没有的
    const differenceSet = new Set(); // {1} 
    this.values().forEach(value => { // {2} 
      if (!otherSet.has(value)) { // {3} 
        differenceSet.add(value); // {4} 
      }
    });
    return differenceSet;
  }
  isSubsetOf(otherSet) {// 判读是不是包含
    if (this.size() > otherSet.size()) { // {1} 
      return false;
    }
    let result = this.values().every(value => otherSet.has(value))
    return result
  }
}
let set = new Set()
set.add(1)
set.add(2)
set.add(3)
let set1 = new Set()
set1.add(5)
set1.add(6)
set1.add(1)
// set1.add(2)
set1.add(3)

console.log(set.isSubsetOf(set1))